package com.wg.dome.entity.user;

import com.wg.common.annotation.DataMember;
import com.wg.common.lang.HashTable;
import com.wg.db.annotation.EntityField;
import com.wg.db.annotation.EntityTable;
import com.wg.dome.attribute.Attribute;
import com.wg.dome.attribute.AttributeHelper;

import java.io.Serializable;

/**
 * 玩家英雄
 */
@EntityTable(tableName = "user_hero", isGrouping = true, groupName = "player_id")
public class HeroEntity implements Serializable {
    /**
     * 唯一id
     */
    @DataMember(code = 1)
    @EntityField(isKey = true)
    private long id;

    /**
     * 静态id
     */
    @DataMember(code = 2)
    @EntityField(fieldName = "s_id")
    private int sId;

    /**
     * 玩家id
     */
    @DataMember(code = 3)
    @EntityField(fieldName = "player_id")
    private long playerId;

    /**
     * 渡劫等级
     */
    @DataMember(code = 4)
    @EntityField(fieldName = "dj_level")
    private short djLv;

    /**
     * 境阶等级
     */
    @DataMember(code = 5)
    @EntityField(fieldName = "jj_level")
    private short jjLv;

    /**
     * 升星等级
     */
    @DataMember(code = 6)
    @EntityField(fieldName = "star_level")
    private short starLv;

    /**
     * 飞升等级
     */
    @DataMember(code = 7)
    @EntityField(fieldName = "fs_level")
    private short fsLv;

    /**
     * 上阵位置 1-6
     */
    @DataMember(code = 8)
    @EntityField(fieldName = "sz_pos")
    private byte szPos;

    /**
     * 布阵位置 1-6
     */
    @DataMember(code = 9)
    @EntityField(fieldName = "bz_pos")
    private byte bzPos;

    /**
     * 属性
     */
    private Attribute attribute;

    /**
     * 是否需要更新属性
     */
    private boolean needUpdateAttribute = true;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public int getsId() {
        return sId;
    }

    public void setsId(int sId) {
        this.sId = sId;
    }

    public short getDjLv() {
        return djLv;
    }

    public void setDjLv(short djLv) {
        this.djLv = djLv;
        this.needUpdateAttribute = true;
    }

    public short getJjLv() {
        return jjLv;
    }

    public void setJjLv(short jjLv) {
        this.jjLv = jjLv;
        this.needUpdateAttribute = true;
    }

    public short getStarLv() {
        return starLv;
    }

    public void setStarLv(short starLv) {
        this.starLv = starLv;
        this.needUpdateAttribute = true;
    }

    public short getFsLv() {
        return fsLv;
    }

    public void setFsLv(short fsLv) {
        this.fsLv = fsLv;
        this.needUpdateAttribute = true;
    }

    public long getPlayerId() {
        return playerId;
    }

    public void setPlayerId(long playerId) {
        this.playerId = playerId;
    }

    public byte getSzPos() {
        return szPos;
    }

    public void setSzPos(byte szPos) {
        this.szPos = szPos;
    }

    public byte getBzPos() {
        return bzPos;
    }

    public void setBzPos(byte bzPos) {
        this.bzPos = bzPos;
    }

    public Attribute getAttribute() {
        if (this.attribute == null || this.needUpdateAttribute){
            this.updateAttribute();
        }
        return attribute;
    }

    public void updateAttribute(){
        this.attribute = AttributeHelper.countHeroAttribute(this);
        this.needUpdateAttribute = false;
    }

    public HashTable toHashTable() {
        HashTable hashTable = new HashTable(20);
        hashTable.put((byte) 1, id);
        hashTable.put((byte) 2, sId);
        hashTable.put((byte) 3, djLv);
        hashTable.put((byte) 4, jjLv);
        hashTable.put((byte) 5, starLv);
        hashTable.put((byte) 6, fsLv);
        hashTable.put((byte) 7, szPos);
        hashTable.put((byte) 8, bzPos);
        return hashTable;
    }
}
